{layout name="./header" /}

<div class="layui-body" style="bottom: 0;border-left: solid 2px #1AA094;" id="container">
    <div class="layui-tab admin-nav-card layui-tab-brief" lay-filter="admin-tab">

        <div class="demoTable">
            搜索ID：
            <div class="layui-inline">
                <input class="layui-input" name="id" id="demoReload" autocomplete="off">
            </div>
            <button class="layui-btn" data-type="reload">搜索</button>
        </div>
        <div class="layui-tab-content" style="min-height: 150px; padding: 5px 0 0 0;">
            <div class="layui-tab-item layui-show">
                <table id="demo"  lay-filter="demo"></table>

            </div>
        </div>
    </div>
</div>

<script src="__STATIC__/plugins/layui/layui.js"></script>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="add">增加</a>
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script>
    layui.use('table', function(){
        var table = layui.table;
        //方法级渲染
        table.render({
            elem: '#demo'
            ,url: '{:url("census/index")}'
            ,cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
            ,cols: [[ //表头
                {checkbox: true, fixed: true}
                ,{field: 'id', title: 'ID',  sort: true}
                ,{field: 'uid', title: '用户',width:'100'}
                ,{field: 'qid', title: '问卷',width:'250', sort: true}
                ,{field: 'wid', title: '问题', width:'250',sort: true}
                ,{field: 'answer', title: '答案', sort: true,align: 'center',width:'300'}
                ,{fixed: 'right', align: 'center', width:'252' , toolbar: '#barDemo'}
            ]]
            ,id: 'testReload'
            ,page: true
        });
        table.on('tool(demo)',function(obj){
            var data = obj.data;
            if(obj.event === 'del'){
                layer.confirm('确认删除行么？', {icon: 3, title:'提示'}, function(index){
                    console.log(666);
                    var id=data.id;
                    $.post('{:url("census/del")}',{id:id},function(respance){
                        console.log(respance);
                        if(respance.code=='200'){
                            layer.msg(respance.msg);
                            layer.close(index);
                            location.reload();
                        }
                    })
                });
            }
            else if(obj.event === 'edit'){
                layer.open({
                    type: 2,
                    maxmin: true,
                    content: 'edit.html?id='+data.id,
                    area: ['400px', '350px'],
                    offset: '100px',
                    btn: ['确定', '取消'],
                    yes:function(){
                        table.reload('demo');
                    }
                });
            }
            else if(obj.event === 'add'){
                layer.open({
                    type: 2,
                    maxmin: true,
                    content: 'add.html',
                    area: ['400px', '350px'],
                    offset: '100px',
                    btn: ['确定', '取消'],
                    yes:function(){
                        table.reload('demo');
                    }
                });
            }
        });
    });
</script>


